package org.tgcloud.group.core.log;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.tgcloud.group.core.APPResultMessage;
import org.tgcloud.group.core.StringUtil;
import org.tgcloud.group.core.custom.Permissions;
import org.tgcloud.group.core.session.Session;
import org.tgcloud.group.entity.*;
import org.tgcloud.group.web.exception.NeedPermissionAspectException;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;

/**
 * @Author: zhy
 * @Created: 2024-07-08-下午5:23
 * @Description:
 */
@Slf4j
@Component
@Aspect
public class LogAspect implements Ordered {

    @Pointcut("@annotation(org.tgcloud.group.core.log.LogRecords)")
    public void logRecords() {
    }


    @Around("logRecords()")
    public Object doLogRecords(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        LogRecords logRecords = method.getAnnotation(LogRecords.class);
        if (logRecords == null) {
            return joinPoint.proceed();
        }

        String value = logRecords.value();
        System.out.println("-------->"+value);
        if (StringUtil.isBlank(value)) {
            return joinPoint.proceed();
        }

        return joinPoint.proceed();
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
